package com.yanqu.road.server.cmd.activity.dragonboatrace;

import com.yanqu.road.entity.activity.dragonboatrace.DragonBoatRaceUnionData;
import com.yanqu.road.pb.dragonboatrace.DragonBoatRaceProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.dragonboatrace.DragonBoatRaceModule;
import com.yanqu.road.server.manger.activity.dragonboatrace.DragonBoatRaceMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.string.StringUtils;


@Cmd(code = GameProtocol.S_DRAGONBOATRACE_ENTER_MAP, desc = "进入龙舟地图")
public class DragonBoatRaceEnterMapCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = DragonBoatRaceMgr.getActivityShowStatus(player);
        if(ret != 0){
            return;
        }
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
            return ;
        }
        DragonBoatRaceModule dragonBoatRaceModule = DragonBoatRaceMgr.getDragonBoatRaceModule(player);

        DragonBoatRaceProto.DragonBoatRaceEnterMapGameToCrossMsg.Builder gameToCrossMsg = DragonBoatRaceProto.DragonBoatRaceEnterMapGameToCrossMsg.newBuilder();
        gameToCrossMsg.setActivityId(DragonBoatRaceMgr.getActivityInfo().getActivityId());
        gameToCrossMsg.setUnionId(unionUid);
        gameToCrossMsg.setPlaceId(dragonBoatRaceModule.dragonBoatRaceUser.baseData.getPlaceId());

        player.sendPacket(CrossProtocol.C2_DRAGONBOATRACE_ENTER_MAP, gameToCrossMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            DragonBoatRaceProto.DragonBoatRaceEnterMapRespMsg.Builder builder = DragonBoatRaceProto.DragonBoatRaceEnterMapRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DRAGONBOATRACE_ENTER_MAP, builder);
        }
    }
}
